From 8f2651280adf042727332a1369298d8c3ecb5afa Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 12 Jan 2006 12:45:49 +0100 Subject: [PATCH] Fix cpu_affinity memcpy() (bytes not longs!) add add a better affinity map sanity check to avoid blowing up Xen if no online cpu is included in the map. Signed-off-by: Keir Fraser --- xen/common/dom0_ops.c | 4 ++-- xen/common/schedule.c | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/xen/common/dom0_ops.c b/xen/common/dom0_ops.c index 42b6c50035..8e7754d84a 100644 --- a/xen/common/dom0_ops.c +++ b/xen/common/dom0_ops.c @@ -323,7 +323,7 @@ long do_dom0_op(dom0_op_t *u_dom0_op) new_affinity = v->cpu_affinity; memcpy(cpus_addr(new_affinity), &op->u.setvcpuaffinity.cpumap, - min((int)BITS_TO_LONGS(NR_CPUS), + min((int)(BITS_TO_LONGS(NR_CPUS) * sizeof(long)), (int)sizeof(op->u.setvcpuaffinity.cpumap))); ret = vcpu_set_affinity(v, &new_affinity); @@ -501,7 +501,7 @@ long do_dom0_op(dom0_op_t *u_dom0_op) op->u.getvcpuinfo.cpumap = 0; memcpy(&op->u.getvcpuinfo.cpumap, cpus_addr(v->cpu_affinity), - min((int)BITS_TO_LONGS(NR_CPUS), + min((int)(BITS_TO_LONGS(NR_CPUS) * sizeof(long)), (int)sizeof(op->u.getvcpuinfo.cpumap))); ret = 0; diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 1493cbddac..20da7f9623 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -207,7 +207,10 @@ void vcpu_wake(struct vcpu *v) int vcpu_set_affinity(struct vcpu *v, cpumask_t *affinity) { - if ( cpus_empty(*affinity) ) + cpumask_t online_affinity; + + cpus_and(online_affinity, *affinity, cpu_online_map); + if ( cpus_empty(online_affinity) ) return -EINVAL; return SCHED_OP(set_affinity, v, affinity); -- 2.30.2